package com.polaris.live.popup

import android.content.Context
import androidx.lifecycle.LifecycleOwner
import com.bumptech.glide.Glide
import com.lxj.xpopup.core.CenterPopupView
import com.polaris.live.R
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.PopupQuestGiftBinding
import com.polaris.live.im.sfs.bean.live.payload.InviteGiftPopupPayloadDto
import com.polaris.live.utils.XPopupUtils
import com.polaris.live.utils.image.ImageUtils

/**
 * 索要礼物弹出消息RequestGiftPopup
 *
 * @author Created by 天晴 on 2024/5/14 20:38
 * @since 1.0.0
 **/
class RequestGiftPopup(
    context: Context,
    private val data: InviteGiftPopupPayloadDto,
    private val onTop: (() -> Unit)? = null,
    private val onBottom: (() -> Unit)? = null,
) : CenterPopupView(context) {

    private lateinit var mBinding: PopupQuestGiftBinding
    override fun getImplLayoutId(): Int {
        return R.layout.popup_quest_gift
    }

    override fun onCreate() {
        super.onCreate()
        mBinding = PopupQuestGiftBinding.bind(popupImplView)

        Glide.with(context)
            .load(ImageUtils.imgPath(data.gift.pic))
            .centerCrop()
            .into(mBinding.iconImg)

        mBinding.nameTv.text = data.gift.giftName
        mBinding.tvTop.setOnSingleClickListener {
            dismiss()
            onTop?.invoke()
        }
        mBinding.tvBottom.setOnSingleClickListener {
            dismiss()
            onBottom?.invoke()
        }
    }

    companion object {

        fun show(
            context: Context,
            owner: LifecycleOwner,
            data: InviteGiftPopupPayloadDto,
            onTop: (() -> Unit)? = null,
            onBottom: (() -> Unit)? = null,
        ) {
            XPopupUtils.showViewPopup(
                RequestGiftPopup(context, data, onTop, onBottom),
                {
                    hasShadowBg(true)
                },
                lifecycle = owner.lifecycle
            )
        }
    }
}